<?php
/**
* @package Pages-and-Items (com_pi_pages_and_items)
* @version 1.5.7
* @copyright Copyright (C) 2006-2010 Carsten Engel. All rights reserved.
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
* @author http://www.pages-and-items.com
*/

//no direct access
if(!defined('_VALID_MOS') && !defined('_JEXEC')){
	die('Restricted access');
}


?>
<link href="components/com_pi_pages_and_items/css/popup.css" rel="stylesheet" type="text/css" />
<?php



$pageId = $class_pi->get_var('itemsPageId');
$selectedPageId = $class_pi->get_var('selectedPageId');

//get link from menuitems
foreach($class_pi->menuitems as $row){
	if($row->id==$pageId){		
		$link = $row->link;		
	}
}

?>
<style type="text/css">

#minwidth{
	min-width: 700px;
}

</style>
<script language="JavaScript" type="text/javascript">

function selectUrl(selectUrl, menuid){	
	window.parent.document.getElementById('href').value = selectUrl;
	window.parent.document.getElementById('targetlist').options[0].selected = true;
	window.parent.document.getElementById('ispopup').checked = false;
	window.parent.document.getElementById('title').value = '';
}

</script>
<?php 
echo "<link href=\"components/com_pi_pages_and_items/css/pages_and_items3.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
echo "<link href=\"components/com_pi_pages_and_items/css/dtree.css\" rel=\"stylesheet\" type=\"text/css\" />\n";
echo "<script src=\"components/com_pi_pages_and_items/javascript/dtree.js\" language=\"JavaScript\" type=\"text/javascript\"></script>\n";
echo "<script src=\"../includes/js/overlib_mini.js\" language=\"JavaScript\" type=\"text/javascript\"></script>\n";

//give headers in Joomla 1.5 a bit more spunk
$class_pi->spunk_up_headers_1_5();
	
//see how many loops we need
$loops = count($class_pi->menutypes);

//loop menutypes
for($m = 0; $m < $loops; $m++){	

	echo '<div class="dtree">';	
	echo '<p><a href="javascript: d'.$m.'.openAll();">'._pi_lang_open_all.'</a> | <a href="javascript: d'.$m.'.closeAll();">'._pi_lang_close_all.'</a></p>';

	//open javascript
	echo "<script type=\"text/javascript\"  type=\"text/javascript\">\n";
	echo "<!--\n";
	//echo "d".$m."_array = new array('d".$m."_array');\n";
	echo "var d".$m."_array = new Array('d".$m."_array');\n";
	echo "d$m = new dTree('d$m');\n";
	echo "d$m.add(0,-1,'";
	echo $class_pi->get_menutype_title($class_pi->menutypes[$m]);	
	echo "','','','','','',true);\n";	

	//make javascript-array from main-menu-items
	foreach($class_pi->menuitems as $row){
		if($row->menutype==$class_pi->menutypes[$m]){
			echo "d$m.add(".$row->id.",".$row->parent.",'".(addslashes($row->name))."','";
			if($row->id!=$pageId){
				if(strpos($row->link, "&Itemid=")){
					$stringItemId = "";
				}else{
					$stringItemId = "&Itemid=".$row->id;
				}
				echo "javascript: selectUrl(\'".$row->link.$stringItemId."\',\'d$m\');";
			}		
			if(((strstr($row->link, 'index.php?option=com_content&view=category&layout=blog') && $row->type=='url') || !strstr($row->link, 'index.php?option=com_content&view=category&layout=blog')) && $row->type!='content_blog_category'){
									echo "','','','components/com_pi_pages_and_items/images/link.gif','components/com_pi_pages_and_items/images/link.gif";		
								}else{
									echo "','','','components/com_pi_pages_and_items/images/page.gif','components/com_pi_pages_and_items/images/page.gif";		
								}
			echo "');\n";
			echo "d".$m."_array.push($row->id);\n";
		}	
	}	
   
	echo "document.write(d$m);\n";
	
	//if a page was already selected, make tree-menu-button selected			
	foreach($class_pi->menuitems as $row){
		if($row->id==$selectedPageId && $row->menutype==$class_pi->menutypes[$m]){			
			echo "d$m.openTo(";
			echo $row->id;
			echo ", true);\n";				
		}					
	}

	//close javascript
	echo "//-->\n";
	echo "</script>\n";
	
	echo '</div>';
	
}//end loop menutypes
?>
</td>
</tr>
</table> 	